<?php

namespace Modules\Buy\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Notification;
use Modules\Buy\Emails\MimaMail;
use Modules\Buy\Entities\Yonghu;
use Modules\Buy\Http\Requests\LoginRequest;
use Modules\Buy\Notifications\MimaCation;

class ForgetController extends Controller
{
    /**
     * Display a listing of the resource.
     * @return Response
     */

//    加载忘记密码视图的路由
    public function forget()
    {
        return view('dlzc.forget');
    }
//    加载忘记密码发送邮件的方法
    public function you(Request $request)
    {


        $res = $request->all();
        $user  = Yonghu::where("email",$res["email"])->first();
//        dd($user->toArray());


        if ($user){
//            dd(123);
//            dd($user->toArray());
//            \Mail::send($user, new MimaMail($user["email"]));
         \Notification::send($user, new MimaCation($user["email"]));
//            session()->flash("success","邮件发送成功，请接收");
            return view("dlzc.jump")->with([
                'message'=>'邮件已经发送,请激活邮件！',
                'url' =>'deng',
                'jumpTime'=>2,
                'name'=>'登录'
            ]);
        }

    }
    public function gaimima($email){
//        加载改密码的模板
        return view("dlzc.gaimima",compact("email"));
    }

//    重置密码
    public function changemima(Request $request){

//        对用户的填写的表单进行验证
        $post = $request->all();
//        echo 111;
//        通过验证
        $user = Yonghu::where("email",$post["email"])->first();
//        dd($user);die;
        $user->password = bcrypt($post["password"]);

//        注意那个first方法
        $user->save();

//        session()->flash("success","恭喜你,密码修改成功");
//        return redirect('/');
        return view('dlzc.jump')->with([
            'message'=>'密码修改成功',
            'url'=>'deng',
            'jumpTime'=>2,
            'name'=>'登录'
        ]);
    }

}
